package com.driving.code.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor

public class ResponseModel<T>{
    /** 状态码 0 失败 1 成功 */
    private int code;
    /** 提示信息 */
    private String message;
    /** 返回结果 */
    private T source;

    public static<T> ResponseModel<T> success(T data){
        ResponseModel<T> responseModel = new ResponseModel<>();
        responseModel.setCode(1);
        responseModel.setSource(data);
        return responseModel;
    }

    public static<T> ResponseModel<T> success(){
        ResponseModel<T> responseModel = new ResponseModel<>();
        responseModel.setCode(1);
        return responseModel;
    }

    public static<T> ResponseModel<T> error(String msg){
        ResponseModel<T> responseModel = new ResponseModel<>();
        responseModel.setMessage(msg);
        responseModel.setCode(0);
        return responseModel;
    }

    public static<T> ResponseModel<T> assignError(Status state){
        ResponseModel<T> responseModel = new ResponseModel<>();
        responseModel.setMessage(state.getMessage());
        responseModel.setCode(state.getCode());
        return responseModel;
    }
}